package management

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

type Config struct {
	ApiPort               int    `json:"apiPort"`
	ApiReadTimeout        int    `json:"apiReadTimeout"`
	ApiWriteTimeout       int    `json:"apiWriteTimeout"`
	WebRoot               string `json:"webroot"`
	UploadFile            string `json:"uploadFile"`
	DownloadFile          string `json:"downloadFile"`
	FileUrl               string `json:"fileUrl"`
	MongodbUri            string `json:"mongodbUri"`
	AppDBName             string `json:"appDBName"`
	MongodbConnectTimeout int    `json:"mongodbConnectTimeout"`
	MINIO_ENDPOINT        string `json:"MINIO_ENDPOINT"`
	MINIO_ACCESS_KEY      string `json:"MINIO_ACCESS_KEY"`
	MINIO_SECRET_KEY      string `json:"MINIO_SECRET_KEY"`
	Minio_bucketName      string `json:"Minio_bucketName"`
	DateOut               string `json:"dateOut"`
	UserCount             int    `json:"userCount"`
}

var (
	G_config *Config
)

func InitConfig(filename string) (err error) {
	var (
		content []byte
		conf    Config
	)
	if content, err = ioutil.ReadFile(filename); err != nil {
		return
	}

	json.Unmarshal(content, &conf)

	G_config = &conf

	fmt.Println(conf)
	return
}
